package com.bawei.fuxi.ui.zhibo;

import com.bawei.fuxi.base.mvp.BasePresenter;
import com.bawei.fuxi.entity.GiftEntity;
import com.bawei.fuxi.entity.LoginEntity;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

public class ZhiBoPresenter extends BasePresenter<ZhiBoContract.IZhiBoView> implements ZhiBoContract.IZhiPresenter {
    private ZhiBoContract.IZhiBoModel mIZhiBoModel;
    public ZhiBoPresenter() {
        mIZhiBoModel = new ZhiBoModel();
    }


    @Override
    public void gift() {
        mIZhiBoModel.gift()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<GiftEntity>() {
                    @Override
                    public void onSubscribe(Disposable d) {
                        mCompositeDisposable.add(d);
                    }

                    @Override
                    public void onNext(GiftEntity gift) {
                        if(isAttach()){
                            getView().showGift(gift);
                        }
                    }

                    @Override
                    public void onError(Throwable e) {
                        if(isAttach()){
                            getView().onError();
                        }
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
}
